home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- * ClassAct Layout Example
- * Copyright ⌐ 1995 Phantom Development Co.
- */
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <intuition/intuition.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/icclass.h>
- #include <libraries/gadtools.h>
-
- #include <graphics/gfxbase.h>
- #include <graphics/text.h>
- #include <graphics/gfxmacros.h>
- #include <utility/tagitem.h>
-
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/diskfont.h>
- #include <proto/utility.h>
-
- #include <stdio.h>
-
- #include <gadgets/classact.h>
-
- /*************************************************************************
- * Some macro defines...
- */
- #define max(x,y) (x > y ? x : y)
- #define min(x,y) (x > y ? y : x)
-
- /*************************************************************************
- * Gadget GA_ID defines for easy meaningful reference
- */
- #define ID_BUTTON1 1L
- #define ID_BUTTON2 2L
- #define ID_BUTTON3 3L
- #define ID_BUTTON4 4L
- #define ID_BUTTON5 5L
- #define ID_BUTTON6 6L
-
- /*************************************************************************
- * Global ClassLibrary Bases for ClassAct
- */
- struct ClassLibrary *ButtonBase = NULL;
- struct ClassLibrary *LayoutBase = NULL;
-
- /*************************************************************************
- * Global pointers to various structures we need...
- */
-
- struct Screen *Scr = NULL;
- struct DrawInfo *draw_info;
-
- /*************************************************************************
- * Closes all ClassAct gadget bases used in the demo
- */
- VOID CloseClassAct(VOID)
- {
- if(LayoutBase)
- {
- CloseLibrary((struct Library *)LayoutBase);
- if(ButtonBase)
- {
- CloseLibrary((struct Library *)ButtonBase);
- }
- }
- }
-
- /*************************************************************************
- * Opens all ClassAct gadget bases used in the demo
- */
- BOOL OpenClassAct(VOID)
- {
- if(LayoutBase=(struct ClassLibrary *)OpenLibrary("gadgets/layout.gadget",0L))
- {
- if(ButtonBase=(struct ClassLibrary *)OpenLibrary("gadgets/button.gadget",0L))
- {
- return(TRUE);
- }
- }
- /* Something failed to open, close down shop.
- */
- CloseClassAct();
- return(FALSE);
- }
-
- /*************************************************************************
- * Main Program
- */
- int main(argc,argv)
- int argc;
- char *argv[];
- {
- struct Window *Win;
- LONG ID;
-
- if(!OpenClassAct())
- {
- Printf("Failed opening ClassAct.\n");
- return(20);
- }
-
- if(argc > 1)
- Scr = LockPubScreen(argv[1]);
- else
- Scr = LockPubScreen("Workbench");
-
- if (Scr == NULL)
- {
- /* Shut down, no screen lock
- */
- Printf("Failed locking public screen.\n");
- CloseClassAct();
- return(5);
- }
-
- draw_info = GetScreenDrawInfo(Scr);
- if(draw_info)
- {
- struct Gadget *gParent, *layout2, *buttonrow;
-
- /* In this example we will create the layout group before opening
- * the window, and size the window to the minimum layout size
- * returned by the LayoutLimits() function, then SetGadgetAttr()
- * will be used to cause the GREL layout group to resize with the window.
- */
- gParent = LayoutObject,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
- LAYOUT_LeftSpacing, INTERWIDTH,
- LAYOUT_RightSpacing, INTERWIDTH,
- LAYOUT_TopSpacing, INTERHEIGHT,
- LAYOUT_BottomSpacing, INTERHEIGHT,
- LAYOUT_BevelStyle, BVS_NONE,
-
- LAYOUT_AddChild, LayoutObject,
- LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
- LAYOUT_LeftSpacing, 0,
- LAYOUT_RightSpacing, 0,
- LAYOUT_TopSpacing, 0,
- LAYOUT_BottomSpacing, 0,
- LAYOUT_AddChild, LayoutObject,
- LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
- LAYOUT_LeftSpacing, INTERWIDTH,
- LAYOUT_RightSpacing, INTERWIDTH,
- LAYOUT_TopSpacing, INTERHEIGHT,
- LAYOUT_BottomSpacing, INTERHEIGHT,
- LAYOUT_BevelStyle, BVS_GROUP,
- LAYOUT_Label, "Horizontal",
- LAYOUT_LabelPlace, BVJ_TOP_CENTER,
- LAYOUT_AddChild, ButtonObject,
- GA_ID, ID_BUTTON1,
- End,
- LAYOUT_AddChild, ButtonObject,
- GA_ID, ID_BUTTON2,
- End,
- LAYOUT_AddChild, ButtonObject,
- GA_ID, ID_BUTTON3,
- End,
- End,
-
- LAYOUT_AddChild, LayoutObject,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
- LAYOUT_LeftSpacing, INTERWIDTH,
- LAYOUT_RightSpacing, INTERWIDTH,
- LAYOUT_TopSpacing, INTERHEIGHT,
- LAYOUT_BottomSpacing, INTERHEIGHT,
- LAYOUT_BevelStyle, BVS_GROUP,
- LAYOUT_Label, "Vertical",
- LAYOUT_LabelPlace, BVJ_TOP_CENTER,
- LAYOUT_AddChild, ButtonObject,
- GA_ID, ID_BUTTON4,
- End,
- LAYOUT_AddChild, ButtonObject,
- GA_ID, ID_BUTTON5,
- End,
- LAYOUT_AddChild, ButtonObject,
- GA_ID, ID_BUTTON6,
- End,
- End,
- End,
-
- LAYOUT_AddChild, buttonrow = LayoutObject,
- LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
- LAYOUT_VertAlignment, LAYOUT_ALIGN_BOTTOM,
- LAYOUT_LeftSpacing, INTERWIDTH,
- LAYOUT_RightSpacing, INTERWIDTH,
- LAYOUT_TopSpacing, INTERHEIGHT,
- LAYOUT_BevelStyle, BVS_SBAR_VERT,
- LAYOUT_Label, "Free, Fixed and Weighted sizes.",
- LAYOUT_LabelPlace, BVJ_TOP_CENTER,
- LAYOUT_ShrinkWrap, FALSE,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "25Kg",
- End,
- CHILD_WeightedWidth, 25,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "50Kg",
- End,
- CHILD_WeightedWidth, 50,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "75Kg",
- End,
- CHILD_WeightedWidth, 75,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "100Kg",
- End,
- CHILD_WeightedWidth, 100,
- End,
- CHILD_WeightedHeight,0,
-
- LAYOUT_AddChild, LayoutObject,
- LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
- LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
- LAYOUT_LeftSpacing, INTERWIDTH,
- LAYOUT_RightSpacing, INTERWIDTH,
- LAYOUT_RightSpacing, INTERWIDTH,
- LAYOUT_BottomSpacing, INTERHEIGHT,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "Free",
- End,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "Fixed",
- End,
- CHILD_WeightedWidth, 0,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "Free",
- End,
- LAYOUT_AddChild, ButtonObject,
- GA_Text, "Fixed",
- End,
- CHILD_WeightedWidth, 0,
- End,
- CHILD_WeightedHeight,0,
- End;
-
- if (gParent)
- {
- struct LayoutLimits Limits;
- struct TextFont *font = OpenFont( Scr->Font );
-
- /* Query parent layout group for min/max layout limits.
- */
- LayoutLimits( gParent, &Limits, font );
-
- CloseFont( font );
-
- if (Win = OpenWindowTags(NULL,
- WA_Flags, WFLG_DEPTHGADGET | WFLG_DRAGBAR |
- WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_SIZEGADGET,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
- IDCMP_GADGETUP | IDCMP_IDCMPUPDATE,
- WA_Top, 20,
- WA_Left, 20,
- WA_InnerWidth, Limits.MinWidth,
- WA_InnerHeight, Limits.MinHeight,
- WA_SmartRefresh, TRUE,
- WA_PubScreen, Scr,
- WA_Title, "ClassAct layout.gadget Example",
- WA_ScreenTitle, "ClassAct Copyright 1995 Phantom Development LLC.",
- TAG_END))
- {
- ULONG wsig = 1L << Win->UserPort->mp_SigBit;
- struct IntuiMessage *msg;
- BOOL done = FALSE;
-
- WORD BorderWidth = Win->BorderLeft + Win->BorderRight;
- WORD BorderHeight = Win->BorderTop + Win->BorderBottom;
-
- WindowLimits(Win,
- Limits.MinWidth + BorderWidth,
- Limits.MinHeight + BorderHeight,
- Limits.MaxWidth + BorderWidth,
- Limits.MaxHeight + BorderHeight);
-
- SetGadgetAttrs( gParent, NULL, NULL,
- GA_Top, Win->BorderTop,
- GA_Left, Win->BorderLeft,
- GA_RelWidth, -BorderWidth,
- GA_RelHeight, -BorderHeight,
- ICA_TARGET, ICTARGET_IDCMP,
- TAG_END);
-
- AddGadget(Win, gParent, -1);
- RefreshGList(gParent, Win, NULL, 1);
-
- while (done == FALSE)
- {
- ULONG sig = Wait(wsig | SIGBREAKF_CTRL_C);
-
- if (sig & wsig)
- {
- while (msg = (struct IntuiMessage *) GetMsg(Win->UserPort))
- {
- switch (msg->Class)
- {
- case IDCMP_CLOSEWINDOW:
- done = TRUE;
- break;
-
- case IDCMP_IDCMPUPDATE:
- {
- USHORT code;
- if (!FindTagItem(LAYOUT_RelVerify, msg->IAddress))
- break;
- code = GetTagData(LAYOUT_RelCode, 0, msg->IAddress);
- switch (GetTagData(GA_ID, 0, msg->IAddress))
- {
- case ID_BUTTON1:
- break;
- case ID_BUTTON2:
- break;
- case ID_BUTTON3:
- break;
- case ID_BUTTON4:
- break;
- case ID_BUTTON5:
- break;
- case ID_BUTTON6:
- break;
- default:
- break;
- }
- }
- break;
-
- default:
- break;
- }
- ReplyMsg((struct Message *) msg);
- }
- }
- else if (sig & SIGBREAKF_CTRL_C)
- {
- done = TRUE;
- }
- }
- RemoveGadget(Win, gParent);
- CloseWindow(Win);
- }
- DisposeObject(gParent);
- }
- FreeScreenDrawInfo(Win->WScreen, draw_info);
- }
- UnlockPubScreen(0, Scr);
- CloseClassAct();
- }
-